#ifndef __H__MVP_NODE_WRITER_H__
#define __H__MVP_NODE_WRITER_H__

#include "transport/transport.h"

namespace motovis
{

template <typename MessageT> class Writer
{
  public:
    using MessagePtr = std::shared_ptr<MessageT>;
    using TransmitterPtr = std::shared_ptr<transport::Transmitter<MessageT>>;

    using TraModPtr = transport::TransportModel;
    Writer(const std::string &channel_name, const TraModPtr& model);
    virtual ~Writer();

    void write(const MessagePtr &msg);

  private:
    TransmitterPtr transmitter_;
    std::string channel_name_;
};

template <typename MessageT>
Writer<MessageT>::Writer(const std::string &channel_name, const TraModPtr& model)
    : channel_name_(channel_name)
{
    transmitter_ =
        transport::Transport::Instance()->createTransmitter<MessageT>(channel_name_, model);
}

template <typename MessageT> Writer<MessageT>::~Writer()
{
    transmitter_ = nullptr;
}

template <typename MessageT> void Writer<MessageT>::write(const MessagePtr &msg)
{
    transmitter_->transmit(channel_name_, msg);
}

} // namespace motovis

#endif //__H__MVP_NODE_WRITER_H__
